home *** CD-ROM | disk | FTP | other *** search
/ Personal Computer World 2005 October / PCWOCT05.iso / Software / FromTheMag / Ant Movie Catalog 3.5.0.2 / amc_install.exe / {app} / Scripts / Yahoo Movies.ifs < prev    next >
Text File  |  2005-03-13  |  4KB  |  119 lines

  1. (***************************************************
  2.  
  3. Ant Movie Catalog importation script
  4. www.antp.be/software/moviecatalog/
  5.  
  6. [Infos]
  7. Authors=NoFiX
  8. Title=Yahoo Movies
  9. Description=Yahoo Movies (Quick Picture Grab)
  10. Site=http://movies.yahoo.com
  11. Language=EN
  12. Version=
  13. Requires=3.5.0
  14. Comments=
  15. License=This program is free software; you can redistribute it and/or modify it under the  terms of the GNU General Public License as published by the Free Software Foundation;  either version 2 of the License, or (at your option) any later version. |
  16. GetInfo=1
  17.  
  18. [Options]
  19.  
  20. ***************************************************)
  21.  
  22. program YahooPictureGrab;
  23. const
  24.   YMGrabPlot = FALSE;
  25. var
  26.   MovieName: string;
  27.  
  28. procedure AnalyzePage(Address: string);
  29. var
  30.   debugPage: TStringList;
  31.   strPage, MovieAddr, MovieTitle, MoviePlot, MovieID: string;
  32.   BeginPos, EndPos: Integer;
  33. begin
  34. //  debugPage:= TStringList.Create;
  35. //  debugPage.Text := GetPage(Address);
  36. //  debugPage.SaveToFile('C:\Yahoo1.txt');
  37.   strPage:= GetPage(Address);
  38.   BeginPos:= Pos('Titles Found</b>', strPage);
  39.   Delete(strPage, 1, BeginPos);
  40.   if(BeginPos > 0) then
  41.     begin
  42.       PickTreeClear;
  43.       PickTreeAdd('Results for ' + MovieName + ':', '');
  44.       BeginPos:= Pos('<a HRef="', strPage);
  45.       while BeginPos > 0 do
  46.         begin
  47.          // Movie Address
  48.           EndPos:= Pos('">', Copy(strPage, BeginPos, Length(strPage) - BeginPos)) + BeginPos - 1;
  49.           MovieAddr:= Copy(strPage, BeginPos + 9, EndPos - BeginPos - 9);
  50.          // Movie Title
  51.           BeginPos:= EndPos + 2;
  52.           EndPos:= Pos('</a>', strPage);
  53.           MovieTitle:= Copy(strPage, BeginPos, EndPos - BeginPos);
  54.          // Add to listbox
  55.           PickTreeAdd(MovieTitle, MovieAddr);
  56.          // Restart the process
  57.           Delete(strPage, 1, EndPos);
  58.           BeginPos:= Pos('<a HRef="', strPage);
  59.         end;
  60.         if(PickTreeExec(Address)) then
  61.           begin
  62.             strPage:= GetPage(Address);
  63.             BeginPos:= FindBefore('<img src="', strPage, Pos('"Movie Image"', strPage));
  64.             if(BeginPos > 0) then
  65.               begin
  66.                 Delete(strPage, 1, BeginPos + 9);
  67.                 EndPos:= Pos('"', strPage);
  68.                 Address:= Copy(strPage, 1, EndPos - 1);
  69.                 GetPicture(Address);
  70.               end
  71.             else
  72.               ShowMessage('No cover-art was found for :' + MovieName);
  73.             // Check if we need plot
  74.             if(GetField(fieldDescription) = '') or (YMGrabPlot = TRUE) then
  75.               begin
  76.                 BeginPos:= Pos('<font face=arial size=-1><b>' + #13, strPage) + 35;
  77.                 ShowMessage(IntToStr(BeginPos));
  78.                 Delete(strPage, 1, BeginPos);
  79.                 EndPos:= Pos('<p>', strPage);
  80.                 MoviePlot:= Copy(strPage, 1, EndPos - 3);
  81.                 HTMLDecode(MoviePlot);
  82.                 SetField(fieldDescription, MoviePlot);
  83.               end;
  84.           end;
  85.     end;
  86. end;
  87.  
  88. Function FindBefore(wordToFind: string; text: string; sPos: Integer):Integer;
  89. var
  90.   iPos, iFound: Integer;
  91. begin
  92.   Text:= Copy(Text, 1, sPos);
  93.  
  94.   iPos:= Pos(wordToFind, Text);
  95.   iFound:= iPos;
  96.   while iPos > 0 do
  97.     begin
  98.       if(iPos > 0) then
  99.           Delete(Text, 1, iPos);
  100.  
  101.       iPos:= Pos(wordToFind, Text);
  102.       iFound:= iFound + iPos;
  103.     end;
  104.    result:= iFound;
  105. end;
  106.  
  107. begin
  108.   if CheckVersion(3,5,0) then
  109.   begin
  110.     MovieName := GetField(fieldOriginalTitle);
  111.     if MovieName = '' then
  112.       MovieName := GetField(fieldTranslatedTitle);
  113.     begin
  114.       AnalyzePage('http://search.movies.yahoo.com/search/movies/title?p=%5B' + UrlEncode(MovieName) + '%5D+type%3Afeature&intl=us&search=title&s=wt,-$s');
  115.     end;
  116.   end else
  117.   ShowMessage('This script requires a newer version of Ant Movie Catalog (at least the version 3.5.0)');
  118. end.
  119.